home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2548 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. Path: news.th-darmstadt.de!news
  2. From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: When to use "->" vs "." when calling Member functions
  5. Date: Thu, 18 Jan 1996 11:33:16 +0100
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Message-ID: <30FE21EC.15FB7483@intellektik.informatik.th-darmstadt.de>
  8. References: <4dhea1$6v8@ornews.intel.com> <30FCB569.41C67EA6@intellektik.informatik.th-darmstadt.de> <4djv40$jpa@epx.cis.umn.edu>
  9. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b5 (X11; I; SunOS 4.1.3 sun4m)
  14.  
  15. Dongxiao Yue wrote:
  16. > Enno Sandner <enno@intellektik.informatik.th-darmstadt.de> writes:
  17. > >Thurman Miller wrote:
  18. > >>
  19. > >> I'm confused, so please no harsh remarks :)
  20. > >>
  21. > >> If I've got:
  22. > >>
  23. > >> class Cfoo
  24. > >> {
  25. > >>         something * getptr();
  26. > >>         somethingelse* m_other;
  27. > >> }
  28. > >>
  29. > >> something * foo::getptr()
  30. > >> {
  31. > >>         return m_other;
  32. > >> }
  33. > >>
  34. > >> Now...if I'm in another class....
  35. > >>
  36. > >>         Cfoo foo;
  37. > >>         somethingelse* = foo.getptr();
  38. > >>
  39. > >> why doesn't the following work?
  40. > >>
  41. > >>         somethingelse* = foo->getptr();
  42. > >>
  43. > >> I get compile error about no "->" overloaded operator....
  44. > >>
  45. > >> Can someone point out the obvious when I use one notation over
  46. > >> another?
  47. > >>
  48. > >If you want to use 'foo.f' where 'f' is some member of a class,
  49. > >'foo' must be an instance or reference to that class. If 'foo'
  50. > >is a pointer to a class you must use 'foo->f' to access the member 'f'.
  51. > >       Enno
  52. >     When you see foo->f,  foo may not be a pointer.
  53.  
  54. That's right. I only said _if_ 'foo' is a pointer to a class you must
  55. use operator '->' not the opposite direction ;-)
  56. So, I guess your remark was intended to be an addition, not a
  57. correction.
  58.  
  59.     Enno
  60.  
  61.  
  62.     Enno
  63.